<script lang="ts">
  import { effect, reactive } from "@feng3d/reactivity";
  import { app } from "../App";

  let count: number = 0;
  let step: number = 1;
  let initialValue: number = 0;

  effect(() => {
    const r_app = reactive(app);

    count = r_app.count;
    step = r_app.step;
    initialValue = r_app.initialValue;
  });
</script>

<div class="counter">
  <h3>🔢 计数器组件</h3>
  <div class="counter-display">
    <span class="count">{count}</span>
  </div>
  <div class="counter-controls">
    <button on:click={() => app.decrementCount()} class="btn-decrement"
      >-</button
    >
    <button on:click={() => app.resetCount()} class="btn-reset">重置</button>
    <button on:click={() => app.incrementCount()} class="btn-increment"
      >+</button
    >
  </div>
  <div class="counter-info">
    <p>步长: {step}</p>
    <p>初始值: {initialValue}</p>
  </div>
</div>

<style>
  .counter {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 20px;
    text-align: center;
    border: 1px solid rgba(52, 152, 219, 0.2);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  }

  .counter h3 {
    margin: 0 0 15px 0;
    color: #2c3e50;
    font-size: 1.2rem;
  }

  .counter-display {
    margin: 20px 0;
  }

  .count {
    font-size: 3rem;
    font-weight: bold;
    color: #2c3e50;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
  }

  .counter-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
  }

  .counter-controls button {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }

  .btn-decrement {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
    color: white;
  }

  .btn-reset {
    background: linear-gradient(45deg, #95a5a6, #7f8c8d);
    color: white;
    width: 80px;
    border-radius: 25px;
    font-size: 1rem;
  }

  .btn-increment {
    background: linear-gradient(45deg, #2ecc71, #27ae60);
    color: white;
  }

  .counter-controls button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  }

  .counter-info {
    margin-top: 15px;
    font-size: 0.9rem;
    color: #7f8c8d;
  }

  .counter-info p {
    margin: 5px 0;
  }

  /* 暗色主题 */
  :global(body.dark-mode) .counter {
    background: rgba(52, 73, 94, 0.95);
    border-color: rgba(52, 152, 219, 0.3);
  }

  :global(body.dark-mode) .counter h3 {
    color: #ecf0f1;
  }

  :global(body.dark-mode) .count {
    color: #ecf0f1;
  }

  :global(body.dark-mode) .counter-info {
    color: #bdc3c7;
  }
</style>
